package edu.nf.bs.service.impl;

import com.github.pagehelper.PageInfo;
import edu.nf.bs.dao.ExpressInfoMapper;
import edu.nf.bs.dao.UserInfoMapper;
import edu.nf.bs.dao.impl.UserInfoMapperImpl;
import edu.nf.bs.entity.ExpressInfo;
import edu.nf.bs.exception.AddException;
import edu.nf.bs.service.ExpressService;

import java.util.List;

public class ExpressServiceImpl implements ExpressService {
    private ExpressInfoMapper expressInfoMapper;

    public void setExpressInfoMapper(ExpressInfoMapper expressInfoMapper) {
        this.expressInfoMapper = expressInfoMapper;
    }

    @Override
    public PageInfo<ExpressInfo> queryExpress(String expressId, Integer pageNum, Integer pageSize) {
        List<ExpressInfo> expressInfos = expressInfoMapper.queryExpress(expressId, pageNum, pageSize);
        PageInfo<ExpressInfo> expressInfoPageInfo = new PageInfo<>(expressInfos);
        return expressInfoPageInfo;
    }

    @Override
    public void addExpress(ExpressInfo express) {

        int r = expressInfoMapper.addExpress(express);
        if(r==1){
            System.out.println("快递信息添加成功");
            return ;
        }
        throw new AddException("快递添加失败！");
    }

    @Override
    public void updateExpress(String expressId,float expressPrice) {
        int r = expressInfoMapper.updateExpress(expressId,expressPrice);
        if(r==0){
            throw new AddException("快递修改失败！");
        }

    }

    @Override
    public ExpressInfo queryExpressId(String expressId) {
        ExpressInfo expressInfo = expressInfoMapper.queryExpressId(expressId);
        return expressInfo;
    }
}
